package DesignPatern.A15_组合模式.QSB.A04_抽象模式;

import java.util.ArrayList;

/**
 * @Author: Du
 * @Date: 2021/8/2 10:53
 * 组合类
 */
public class Composite extends Component
{
    private ArrayList<Component> components = new ArrayList<>();
    
    public void add(Component component)
    {
        this.components.add(component);
    }
    
    public void remove(Component component)
    {
        this.components.remove(component);
    }
    
    public ArrayList<Component> getChildren()
    {
        return this.components;
    }
    
    @Override
    public int Count()
    {
        int sum = 0;
        for (Component counter : this.components)
        {
            sum += counter.Count();
        }
        return sum;
    }
}
